<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="./jquery-1.4.4.js" type="text/javascript"></script>
<script>
	$(function(){
	
		$("#userId").blur(function(){
			var userValue = $(this).val();
			$("#spanId").text("");
			$.ajax({
				type: "POST",
				url: "<c:url value='/ValidateUserNameServlet'/>",
				data: "username="+userValue,
				dataType:"text",
				success: function(msg){
					// 对服务器端返回的信息 显示在span标签中
					if(msg=="1"){
						$("#spanId").text("该用户名已经注册过了");
					}else if(msg=="2"){
						$("#spanId").text("用户名注册非法");
					}else{
						$("#spanId").text("用户名注册合法");
					}
				},
			});
		});
	
	
	
	});


</script>

<title>Insert title here</title>
</head>
<body>
<h1>验证用户名名是否注册使用异步操作</h1>
<form action="" method="post" >
用户名：<input type="text" name="usrname" id="userId"/>
<span color="red" id="spanId"></span><br/>
密码：<input type="password" name="password"/><br/>
<input type="submit" value="提交"/>


</form>
</body>
</html>